package com.springx.examples.showcase.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.springx.examples.showcase.entity.Area;
import com.springx.examples.showcase.repository.mybatis.AreaMapper;
import com.springx.examples.showcase.vo.tree.AreaVo;

import org.javasimon.aop.Monitored;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Component
@Transactional
@Monitored
public class AreaService  extends  BaseService<Area> {
    @Autowired
    private AreaMapper areaMapper;
    /*
    * 自定义查找
    * */
    public List<AreaVo>  findList(Map<String, Object> params){

        return  areaMapper.findList(params);
    };
    /*
    * 分页查询
    *
    * */
   public Page<AreaVo>  findPage(Map<String, Object> params, Pageable pageable){
       PageHelper.startPage((pageable.getPageNumber() - 1) * pageable.getPageSize(), pageable.getPageSize());
       List<AreaVo>  list=areaMapper.findList(params);
       PageInfo<AreaVo> pageInfo = new PageInfo<>(list);
       Page<AreaVo> page = new PageImpl<AreaVo>(pageInfo.getList(), pageable, pageInfo.getTotal());
       return page;
   }

 }
